package binarysearch.test162;

/**
 * 寻找峰值
 *
 * @author code_yc
 * @version 1.0
 * @date 2020/7/11 11:10
 */
public class Solution1 {

    public int findPeakElement(int[] nums) {
        return helper(nums, 0, nums.length - 1);
    }

    private int helper(int[] nums, int l, int r) {
        if (l == r) return l;

        int mid = (l + r) >>> 1;
        if (nums[mid] < nums[mid + 1]) {
            return helper(nums, mid + 1, r);
        } else {
            return helper(nums, l, mid);
        }
    }
}
